package cn.com.cifi.mars.bean.bo.returnPlan;

import cn.com.cifi.mars.bean.dto.returnPlan.ReturnSignMyReceiptsDto;
import cn.com.cifi.mars.bean.dto.returnPlan.ReturnSignReceivableDto;
import cn.com.cifi.mars.bean.dto.returnPlan.ReturnSignRecordsDto;
import cn.com.cifi.mars.util.LocalDateTimeUtils;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.MapUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 回款明源签约数据
 * @author: JingYuanXiang
 * @date: 2020/11/12 15:08
 */
@Data
public class ReturnPlanSaleDataBO{
    @ApiModelProperty(name = "returnSignRecordsList", value = "签约记录列表")
    List<ReturnSignRecordsDto> returnSignRecordsList;

    @ApiModelProperty(name = "recordsRoomIdListByGroupIdMap", value = "签约记录Map(key:组团id,value:(key:组合业态编码,value:合同id列表))")
    Map<String,Map<String, List<String>>> recordsRoomIdListByGroupIdMap = new HashMap();

    @ApiModelProperty(name = "lastReceivableTimeByGroupIdMap", value = "最晚应收时间Map(key:组团id,value:(key:组合业态编码,value:年月)")
    Map<String, Map<String, String>> lastReceivableTimeByGroupIdMap = new HashMap();

    @ApiModelProperty(name = "recordsMoneyByRoomIdMap", value = "签约记录Map(key:组团id,value:(key:组合业态编码,value:(key:房间id,value:(key:年月,value:金额))")
    Map<String,Map<String,Map<String, Map<String, BigDecimal>>>> recordsMoneyByGroupIdMap = new HashMap();

    @ApiModelProperty(name = "receiptsMoneyByGroupIdMapA", value = "签约实收Map(key:组团id,value:(key:组合业态编码,value:(key:年月,value:(key:合同id,value:金额))")
    Map<String,Map<String,Map<String, Map<String, BigDecimal>>>> receiptsMoneyByGroupIdMapA = new HashMap();

    @ApiModelProperty(name = "receiptsMoneyByGroupIdMap", value = "签约实收Map(key:组团id,value:(key:组合业态编码,value:(key:年月,value:(key:房间id,value:金额))")
    Map<String,Map<String,Map<String, Map<String, BigDecimal>>>> receiptsMoneyByGroupIdMapB = new HashMap();

    @ApiModelProperty(name = "zlReceiptsMoneyByGroupIdMap", value = "签约增量实收Map(key:组团id,value:(key:组合业态编码,value:(key:年月,value:金额))")
    Map<String,Map<String,Map<String, BigDecimal>>> zlReceiptsMoneyByGroupIdMap = new HashMap();

    @ApiModelProperty(name = "clReceiptsMoneyByGroupIdMap", value = "签约存量实收Map(key:组团id,value:(key:组合业态编码,value:(key:年月,value:金额))")
    Map<String,Map<String,Map<String, BigDecimal>>> clReceiptsMoneyByGroupIdMap = new HashMap();

    //初始化Map
    public void initializeMap(){

    }

    /**
     * 获取最晚应收时间
     * @param groupId 组团id
     * @param combinationProductCode 组合业态编码
     * @return
     */
    public LocalDateTime getLastReceivableTime(String groupId,String combinationProductCode){
        if(CollectionUtils.isNotEmpty(lastReceivableTimeByGroupIdMap.get(groupId))
                && StringUtils.isNotEmpty(lastReceivableTimeByGroupIdMap.get(groupId).get(combinationProductCode))){
             return LocalDateTimeUtils.toLocalDateTime(lastReceivableTimeByGroupIdMap.get(groupId).get(combinationProductCode));
        }
        return null;
    }

    /**
     * 获取签约增量实收
     * @param combinationProductCode 组合业态编码
     * @param yearMonth 年月
     * @return
     */
    public BigDecimal getZlReceiptsMoneyByYearMonth(String groupId,String combinationProductCode, String yearMonth) {
        return BigDecimal.ZERO;
    }

    /**
     * 获取签约存量实收
     * @param combinationProductCode 组合业态编码
     * @param yearMonth 年月
     * @return
     */
    public BigDecimal getClReceiptsMoneyByYearMonth(String groupId,String combinationProductCode, String yearMonth) {
        return BigDecimal.ZERO;
    }

    /**
     * 获取签约实收
     * @param combinationProductCode 组合业态编码
     * @param yearMonth 年月
     * @return
     */
    public BigDecimal getReceiptsMoneyByYearMonth(String groupId,String combinationProductCode, String yearMonth) {
        return BigDecimal.ZERO;
    }

    /**
     * 获取月初应退
     * @param groupId 组团id
     * @param combinationProductCode 组合业态编码
     * @param yearMonth 年月
     * @return
     */
    public BigDecimal getRefundable(String groupId,String combinationProductCode, String yearMonth) {
        return BigDecimal.ZERO;
    }

    /**
     * 比较两个年月大小
     * -1 小于
     * 0 等于
     * 1 大于
     * @param yearMontA yyyy-mm
     * @param yearMonthB yyyy-mm
     * @return
     */
    public int compareYearMonth(String yearMontA, String yearMonthB) {
        String[] splitA = yearMontA.split("-");
        String[] splitB = yearMonthB.split("-");

        int yearA = Integer.parseInt(splitA[0]);
        int monthA = Integer.parseInt(splitA[1]);
        int yearB = Integer.parseInt(splitB[0]);
        int monthB = Integer.parseInt(splitB[1]);

        int compare = Integer.compare(yearA, yearB);
        if(compare == 0){
            compare = Integer.compare(monthA, monthB);
        }
        return compare;
    }


}
